<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2014/10/11
 * Time: 16:30
 */
class ManageUserProject extends CActiveRecord{
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return 'manage_user_project';
    }
    const ALL_PROJECT = -1;//所有项目
    /**
     * 通过用户得到用户管理的项目
     */
    public function getByUser($user_id){
        $data = $this->findAll('user_id=:user_id', array(':user_id' => $user_id));
        $result = array();
        if ($data) {
            foreach ($data as $key => $val) {
                if ($val['project_id'] == -1) {
                    $result = self::ALL_PROJECT;
                    break;
                }
                $result[] = $val['project_id'];
            }
        }
        return $result;
    }
    /**
     * 通过项目查找哪些用户管理
     */
    public function getByProject($project_id){
        $data = $this->findAll('project_id=:project_id', array(':project_id' => $project_id));
        $result = array();
        if ($data) {
            foreach ($data as $key => $val) {
                $result[] = $val['user_id'];
            }
        }
        return $result;
    }
}